package com.csg.ses.controller;

import com.csg.ses.common.annotation.LoginToken;
import com.csg.ses.entity.ses.SysRoleTypeEntity;
import com.csg.ses.service.ses.SysRoleTypeService;
import com.csg.ses.vo.common.IdListVo;
import com.csg.ses.vo.common.Result;
import com.csg.ses.vo.common.ResultStatus;
import com.csg.ses.vo.list.RoleTypeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 角色类型
 * @author wangjun
 * @date 2020/11/16
 */
@RestController
@RequestMapping("/role-type")
@Api(tags = "角色类型接口")
public class SysRoleTypeController {
    @Autowired
    private SysRoleTypeService sysRoleTypeService;

    /**
     * 列表
     */
    @ApiOperation(value = "角色类型")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "type", value = "角色类型", dataType = "SysRoleTypeEntity", paramType = "body"),
        @ApiImplicitParam(name = "current", value = "当前页", required = true ,dataType = "Integer"),
        @ApiImplicitParam(name = "size", value = "每页记录数", required = true ,dataType = "Integer")
    })
    @GetMapping("/list")
    @LoginToken
    public Result<List<SysRoleTypeEntity>> list(SysRoleTypeEntity type, Long current, Long size) {
        return sysRoleTypeService.retrieve(type, current, size);
    }

    /**
     * 角色类型下拉数据
     * @return
     */
    @ApiOperation(value = "角色类型下拉数据")
    @GetMapping("/drop-data")
    @LoginToken
    public Result dropData() {
        return sysRoleTypeService.dropData();
    }

    /**
     * 删除角色类型
     * @param idList
     * @return
     */
    @ApiOperation(value = "删除角色类型")
    @ApiImplicitParam(name = "idList", value = "角色类型ID数组", dataType = "IdListVo", paramType = "body", required = true)
    @DeleteMapping("/del")
    @LoginToken
    public Result del(@RequestBody IdListVo idList) {
        return sysRoleTypeService.del(idList);
    }

    @ApiOperation(value = "根据id查找角色类型")
    @ApiImplicitParam(name = "id", value = "角色类型id", dataType = "String", required = true)
    @GetMapping("/{id}")
    @LoginToken
    public Result<SysRoleTypeEntity> getById(@PathVariable String id) {
        return sysRoleTypeService.getById(id);
    }

    /**
     * 保存角色类型
     * @param roleTypeVo
     * @return
     */
    @ApiOperation(value = "保存角色类型")
    @ApiImplicitParam(name = "roleTypeVo", value = "角色类型数组", dataType = "RoleTypeVo", paramType = "body", required = true)
    @PostMapping("/save")
    @LoginToken
    public Result<String> save(@RequestBody RoleTypeVo roleTypeVo) {
        return new Result(sysRoleTypeService.save(roleTypeVo), ResultStatus.SUCCESS);
    }
}